import request from "./request";

//登录接口
export const login = (params) => {
	uni.showLoading();
	return request({
		url: '/user/login',
		method: 'post',
		data: params,
		header: {}
	})
}
//注册用户
export const register = (params) => {
	uni.showLoading();
	return request({
		url: '/user/register',
		method: 'post',
		data: params,
		header: {}
	})
}
//跟换头像
export const updateAvatar = (params) => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			//http://192.168.254.133:80
			url: 'http://xuanhao.free.idcfengye.com/api/user/updateAvatar',
			filePath: params.path,
			name: 'avatar',
			formData: {
				'id': params.id
			},
			success(response) {
				const res = response
				if (res.statusCode == 200 || (res.data.code >= 200 && res.data.code <= 400)) {
					resolve(res.data);
				}else{
					uni.showToast({
						title: res.data.msg,
						icon:"error",
						duration: 2000,
					})
				}
			}
		});
	});
}
//获取头像
export const getAvatar = (params) => {
	return request({
		url: '/user/getAvatar',
		method: 'get',
		data: params,
		header: {}
	})
}
//退出登录
export const outLogin = (params) => {
	return request({
		url: '/user/outLogin',
		method: 'get',
		data: params,
		header: {}
	})
}
//获取验证码
export const captcha = (params) => {
	return request({
		url: '/user/captcha',
		method: 'get',
		data: params,
		responseType: 'arraybuffer',
		header: {}
	})
}
//修改密码
export const setPwdCaptcha = (params) => {
	return request({
		url: '/user/setPwdCaptcha',
		method: 'post',
		data: params,
		header: {}
	})
}

/**
 * 会话相关api
 */
// 刷新会话列表
export const refreash = (params) => {
	return request({
		url: '/conversation/list',
		method: 'get',
		data: params,
		header: {}
	})
}
//设置聊天窗口为置顶
export const setTop = (params) => {
	return request({
		url: '/conversation/top',
		method: 'get',
		data: params,
		header: {}
	})
}
//取消聊天窗口置顶
export const setCancelTop = (params) => {
	return request({
		url: '/conversation/cancelTop',
		method: 'get',
		data: params,
		header: {}
	})
}
//删除聊天窗口
export const deleteConversation = (params) => {
	return request({
		url: '/conversation/delete',
		method: 'get',
		data: params,
		header: {}
	})
}
//获取窗口详情
export const getDetail = (params) => {
	return request({
		url: '/conversation/detail',
		method: 'get',
		data: params,
		header: {}
	})
}


/**
 * 消息相关api
 */
//清楚已读
export const clearRead = (params) => {
	return request({
		url: '/message/clear',
		method: 'get',
		data: params,
		header: {}
	})
}
//获取消息
export const getMsgList = (params) => {
	return request({
		url: '/message/list',
		method: 'get',
		data: params,
		header: {}
	})
}
//发送消息
export const sendMsg = (params) => {
	return request({
		url: '/message/send',
		method: 'get',
		data: params,
		header: {}
	})
}
//删除消息
export const deleteMsg = (params) => {
	return request({
		url: '/message/delete',
		method: 'get',
		data: params,
		header: {}
	})
}


/**
 * 用户好友api
 */
//查询用户详情
export const getUserDetail = (params) => {
	return request({
		url: '/friend/getFriendDetails',
		method: 'get',
		data: params,
		header: {}
	})
}
//模糊查询好友
export const getFriendList = (params) => {
	return request({
		url: '/user/getFriendAll',
		method: 'get',
		data: params,
		header: {}
	})
}
//根据用户名和账号模糊查询
export const getUserAll = (params) => {
	return request({
		url: '/user/getUserAll',
		method: 'get',
		data: params,
		header: {}
	})
}
//根据id查询用户
export const getUserById = (params) => {
	return request({
		url: '/user/getUserById',
		method: 'get',
		data: params,
		header: {}
	})
}
//推荐共同好友
export const getCommonFriends = (params) => {
	return request({
		url: '/friend/getCommonFriends',
		method: 'get',
		data: params,
		header: {}
	})
}
//查询好友列表
export const getFriends = (params) => {
	return request({
		url: '/friend/getFriends',
		method: 'get',
		data: params,
		header: {}
	})
}
//查询好友请求列表
export const getRequestFriend = (params) => {
	return request({
		url: '/friend/getRequestFriend',
		method: 'get',
		data: params,
		header: {}
	})
}
//添加好友
export const addFriend = (params) => {
	return request({
		url: '/friend/addFriend',
		method: 'post',
		data: params,
		header: {}
	})
}
//获取验证详情内容
export const getValidate = (params) => {
	return request({
		url: '/friend/getValidate',
		method: 'get',
		data: params,
		header: {}
	})
}
//同意好友申请
export const setFriendAgree = (params) => {
	return request({
		url: '/friend/setFriendAgree',
		method: 'get',
		data: params,
		header: {}
	})
}
//删除好友
export const deleteFriend = (params) => {
	return request({
		url: '/friend/deleteFriend',
		method: 'get',
		data: params,
		header: {}
	})
}